/**
 * @file PMT.h
 *
 * @author Luc Fourestier
 * @date 2009
 */

#ifndef PMT_H_
#define PMT_H_

#include <stdio.h>

// Errors
#define PMT_ERROR_NOT_A_PMT 1

#define PMT_TID 0x2

#define MAX_STREAM_DESC 10

/**
 * The stream descriptor
 */
typedef struct PMT_StreamDesc_s
{
	unsigned char stream_type;
	unsigned char reserved_1;
	unsigned short elementary_PID;
	unsigned char reserved_2;
	unsigned short ES_info_length;
	// Skip descriptors
} PMT_StreamDesc_t;

/**
 * The PMT
 */
typedef struct PMT_s
{
	unsigned char table_id;
	unsigned char section_syntax_indicator;
	unsigned char zero;
	unsigned char reserved_1;
	unsigned short section_length;
	unsigned short transport_stream_id;
	unsigned char reserved_2;
	unsigned char version_number;
	unsigned char current_next_indicator;
	unsigned char section_number;
	unsigned char last_section_number;
	unsigned char reserved_3;
	unsigned short PCR_PID;
	unsigned char reserved_4;
	unsigned short program_info_length;

	// skip Descriptors

	unsigned int StreamDescNumber;
	PMT_StreamDesc_t stream_descriptors[MAX_STREAM_DESC];

	unsigned int CRC_32;
}PMT_t;

/**
 * @brief Fill the PMT
 */
int PMT_Create(unsigned char * Buffer, unsigned int *Size, PMT_t * PMT);

/**
 * @brief Print the PMT
 */
int PMT_Print(PMT_t * PMT, char * Name, int level, FILE * Output);

/**
 * @brief Check the PMT validity
 */
int PMT_CheckPMT(unsigned char * Buffer, unsigned int Size);

#endif /* PMT_H_ */
